<?php


namespace app\api\v1\graphQLModel;


use app\api\community\utils\IpUtil;
use app\api\v1\graphQLModel\fieldType\ipFieldType;
use GraphQL\Type\Definition\ResolveInfo;
use iflow\Swoole\GraphQL\Annotation\Type\lib\ArgsType;
use iflow\Swoole\GraphQL\Annotation\Type\lib\fieldType;
use iflow\Swoole\GraphQL\Annotation\Type\lib\resolveType;
use iflow\Swoole\GraphQL\Annotation\Type\TypeAnnotation;

#[TypeAnnotation('ip')]
class IpDbGraphQL
{

    #[fieldType('ipv4', ipFieldType::class, '获取ipv4数据')]
    #[ArgsType([
        'ip' => [
            'type' => 'nonNull->string'
        ]
    ])]
    #[resolveType(IpDbGraphQL::class.'@getIpv4Map')]
    public array $ipv4;

    #[fieldType('ipv6', 'string', '获取ipv6数据')]
    #[ArgsType([
        'ip' => [
            'type' => 'nonNull->string'
        ]
    ])]
    #[resolveType(IpDbGraphQL::class.'@getIpv4Map')]
    public array $ipv6;


    public function getIpv4Map($rootValue, array $args, $context, ResolveInfo $resolveInfo): array
    {
        return (new IpUtil) -> get_ipv4_find_map($args['ip']) ?: [];
    }

}